package com.innovate.nms.domain;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.ivan.toolkit.common.Configs;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
@NoArgsConstructor
public class AppConfig {
	
	public static Configs.Instance<AppConfig> instance = 
			new Configs.Instance<AppConfig>(AppConfig.class, true);	
	
	@XmlAttribute
	@Setter @Getter
	private String localName = "";
	
	@XmlAttribute
	@Setter @Getter
	private String localSMS = "";
	
	@XmlElement
	@Setter @Getter
	private NetNode emu1 = new NetNode("emu1", true, "192.168.0.1", "13912345678");
	
	@XmlElement
	@Setter @Getter
	private NetNode emu2 = new NetNode("emu2", true, "192.168.0.1", "13912345678");
	
	@XmlElement
	@Setter @Getter
	private NetNode emu3 = new NetNode("emu3", true, "192.168.0.1", "13912345678");

	@XmlElement
	@Setter @Getter
	private NetNode rtu = new NetNode("rtu", false, "192.168.0.1", null);
		
	
	public String getString(String node, boolean wired) {
		
		if(wired) {
			
			switch(node.toLowerCase()) {
			case "emu1":return getEmu1().getIp();
			case "emu2":return getEmu2().getIp();
			case "emu3":return getEmu3().getIp();
			case "rtu":return getRtu().getIp();
			default: return null;
			}
			
		} else {
			
			switch(node.toLowerCase()) {
			case "emu1":return getEmu1().getSms();
			case "emu2":return getEmu2().getSms();
			case "emu3":return getEmu3().getSms();
			default: return null;
			}
		}
		
	}
	
	public String getName(String node) {
		
		switch(node.toLowerCase()) {
		case "ems":return getLocalName();
		case "emu1":return getEmu1().getName();
		case "emu2":return getEmu2().getName();
		case "emu3":return getEmu3().getName();
		case "rtu":return getRtu().getName();
		default: return null;
		}
		
	}

}
